myApp.stores.IndexLinks = new Ext.data.Store({
    model:'IndexLinks',
    sorters: ['controller','action'],
    data:[
        { id: 1,  controller: "Index",  action:"index", html:"", timeElapsed:0},
        { id: 2,  controller: "Index",  action:"panel", html:"", timeElapsed:0},
        { id: 3,  controller: "Index",  action:"toolbar", html:"", timeElapsed:0},
        { id: 4,  controller: "Index",  action:"tabpanel", html:"", timeElapsed:0},
        { id: 5,  controller: "Index",  action:"carousel", html:"", timeElapsed:0},
        { id: 6,  controller: "Index",  action:"box", html:"", timeElapsed:0},
        { id: 7,  controller: "Contact",  action:"index", html:"", timeElapsed:0}
    ],
    init: function(){
        this.initLoadData();
    },
    initLoadData:function(){
        if(localStorage.getItem('indexLinks').split(',').length >= 7){
            console.log('initLoadData',true);
            this.load({
                scope:this,
                callback:function(records,operation,success){
                    console.log('records',records);
                    console.log('operation',operation);
                    console.log('success',success);
                }
            })
        }
        else{
            console.log('initLoadData',false);
        }
    },
    proxy:{
        type:'localstorage',
        id:'indexLinks'
    },
    getRecordByControllerAction: function(controller,action){
        var idLinkRecord = this.findBy(function(record,id){
            //console.info('findBy',record.get('controller')+'/'+record.get('action'),'id',id,'record',record);
            if(record.get('controller') == controller && record.get('action') == action)
                return true;
        });
        //console.info('idLinkRecord',idLinkRecord)
        if(idLinkRecord != -1)
            return this.getAt(idLinkRecord);
    },
    getTimeElapsed: function(controller,action){
        var linkRecord = this.getRecordByControllerAction(controller,action);
        if(linkRecord)
            return linkRecord.get('timeElapsed');
        else
            return 0;
    },
    updateTimeElapsed : function(controller,action,flagSaveData){
        var timeElapsed = myApp.helpers.timer.getTimeElapsed();
        var linkRecord = this.getRecordByControllerAction(controller,action);
        //console.info('IndexLinks.js - timeElapsed : ',timeElapsed, 'controller',controller,'action',action,'record',linkRecord);
        if(linkRecord){
            //console.info('linkRecord',linkRecord);
            linkRecord.set('timeElapsed',timeElapsed);
        }
        if(flagSaveData && flagSaveData == true)
            this.saveAll();
    },
    saveAll: function(){
        myApp.stores.IndexLinks.sync();
    }
})